/*
 * LcfsScheduler.cc
 *
 *  Created on: 2011-04-15
 *      Author: awjastrzebski
 */

#include "LcfsScheduler.h"

Define_Module(LcfsScheduler)

void LcfsScheduler::initialize()
{
	AbstractScheduler::initialize();
	maxQueueSize = par("maxQueueSize");
}

bool LcfsScheduler::receivePacket(NetPacket* packet, int gateNum)
{
	if(canReceive())
	{
		awaitingPackets.push_back(packet);
		return true;
	}
	else
		return false;
}

bool LcfsScheduler::hasPacketsAwaitingDeparture()
{
	return !awaitingPackets.empty();
}

NetPacket* LcfsScheduler::getPacketForDeparture()
{
	NetPacket* pck = awaitingPackets.back();
	awaitingPackets.pop_back();

	return pck;
}

bool LcfsScheduler::canReceive()
{
	return awaitingPackets.size() < maxQueueSize || !maxQueueSize;
}
